package dao.postgres;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import dao.DAOFactory;
import dao.ContaDAO;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PostgresDAOFactory extends DAOFactory {

	private static Connection conn;
	
	public PostgresDAOFactory(){
	//	getConnection();
		conn = null;
	}
	
	public static Connection getConnection(){
                try {
                    Class.forName("org.postgresql.Driver");
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(PostgresDAOFactory.class.getName()).log(Level.SEVERE, null, ex);
                }
		
		if(conn != null) return (conn);
		String url = "jdbc:postgresql://localhost/disputando";
		String user = "roberto";
		String passwd = "security";
		try {
			conn = DriverManager.getConnection(url,user,passwd);
			System.out.println("Connection sucess");
		} catch (SQLException e) {			
			e.printStackTrace();
		}
		return (conn);		
	}

	@Override
	public ContaDAO getContaDAO() {
		return (new PostgresContaDAO());
	}
}
